package com.wust.supermarket.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wust.supermarket.dao.StaffDao;
import com.wust.supermarket.domain.Staff;
import com.wust.supermarket.service.StaffService;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

	@Autowired
	private StaffService staffService;
	
	@PostMapping("/login")
	public String login(String staﬀUsername, String staﬀPassword, Model model, HttpSession httpSession) {
		Staff staff=staffService.getStaffByName(staﬀUsername, staﬀPassword);
		httpSession.setAttribute("staffId",staff.getStaffId());
		if(staff!=null) {
			return "index";
		}else {
			model.addAttribute("msg", "账号或密码错误");
			return "login";
		}
	}
	
	@RequestMapping("/toLogin")
	public String toLogin() {
		return "login";
	}
	
	
	
}
